class Solution {
public:
    int triangleNumber(vector<int>& nums) {
       sort(nums.begin(), nums.end());//将数组排成升序
        int max_edge = nums.size() - 1;//最长边
        int count = 0;//构成三角形的三元组计数

        while (max_edge > 1)
        {
            int left = 0;
            int right = max_edge - 1;
            while (left < right)
            {
                if (nums[left] + nums[right] > nums[max_edge])//较小两边之后大于第三边
                {
                    count += right - left;
                    right--;
                }
                else
                    left++;
            }
            max_edge--;
        }
        return count;
    }
};